import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  strict: true,//严格模式，只能用action来修改state
  state: {
     currentUser:window.localStorage.getItem('cuser') ? JSON.parse(window.localStorage.getItem('cuser')) : {},
     currentPlay:  {
      "key": 1,
      "img_url":"./img/huahai.png",
      "singer":"未知歌手",
      "name": "花海",
      "url": "./music_list/Naive_ - 花海 (女生版).mp3"
    }
  
    },
  mutations: {
    currentUser (state, user) {
      state.currentUser = user
      // 登陆完成将用户信息存储在localStorage
      window.localStorage.setItem('cuser',JSON.stringify(user))
    },
    currentPlay (state, item) {
      state.currentPlay = item
      // 登陆完成将用户信息存储在localStorage
    }
  },
  actions: {
    setUser (context, user) {
      context.commit('currentUser', user)
    },
    musicItem (context, item) {
      context.commit('currentPlay', item)
    },
  },
  modules: {
  }
})
